package provider;

import anaydis.sort.Sorter;
import anaydis.sort.SorterType;
import anaydis.sort.provider.SorterProvider;
import implementation.sort.*;
import implementation.sort.QuickSort.QuickSortCutOff;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;


public class SorterProviderImpl implements SorterProvider {
    private Map<SorterType, Sorter> map;

    public SorterProviderImpl() {
        map = new EnumMap<SorterType, Sorter>(SorterType.class);
        map.put(SorterType.BUBBLE, new BubbleSort());
        map.put(SorterType.SELECTION, new SelectionSort());
        map.put(SorterType.INSERTION, new InsertionSort());

        ShellSorter shell = new ShellSorter();
        shell.setSequence(getSequence());

        map.put(SorterType.SHELL, shell);
        map.put(SorterType.QUICK_CUT, new QuickSortCutOff());
        map.put(SorterType.HEAP, new HeapSort());
    }

    private List<Integer> getSequence() {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        return list;
    }

    @NotNull
    public Sorter getSorterForType(@NotNull SorterType sorterType) {
        return map.get(sorterType);
    }

    @NotNull
    public Iterable<Sorter> getAllSorters() {
        return map.values();
    }
}
